package join_yield;

public class Join implements Runnable {
    static Object object = new Object();
    static int i = 0;

    @Override
    public void run() {
        synchronized (object) {
        for (int j = 0; j < 100; j++) {
            i++;
        }
        }
    }

    public static void main(String[] args) throws InterruptedException {
        Thread t1 = new Thread(new Join());
        Thread t2 = new Thread(new Join());
        t1.start();
        t2.start();

        //  主线程等这个线程执行完，主线程才执行下一行代码。相当于wait等待中
        t1.join();
        t2.join();
        //不写join是<200，写了是200.
        System.out.println(Join.i);
    }
}
